/**
 * 
 */
$(function(){		
	var depart = $('#department');
	var region = $('#region');
	var building = $('#building');
	var room = $('#room');
	var devicetype = $('#devicetype');
	depart.append("<option value=''>--请选择--</option>");
	region.append("<option value=''>--请选择--</option>");
	building.append("<option value=''>--请选择--</option>");
	room.append("<option value=''>--请选择--</option>");
	devicetype.append("<option value=''>--请选择--</option>");
	$.ajax({
		type : 'post',
		url : 'department/getDepartment.action',
		dataType : 'json',
		success : function(data) {
			for(var i=0; i<data.length; i++) {
				depart.append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
			}					
		}
	});
	$.ajax({
		type : 'post',
		url : 'region/getRegion.action',
		dataType : 'json',
		success : function(data) {
			for(var i=0; i<data.length; i++) {
				region.append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
			}					
		}
	});
});

function onBuilding() {
	var building = $('#building');
	var room = $('#room');
	var regionId = $('#region').val();
	building.empty();
	room.empty();
	building.append("<option value=''>--请选择--</option>");
	$.ajax({
		type : 'post',
		url : 'build/getBuilding.action?regionId=' + regionId,
		dataType : 'json',
		success : function(data) {
			for(var i=0; i<data.length; i++) {
				building.append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
			}					
		}
	});
}

function onRoom() {
	var room = $('#room');
	var buildingId = $('#building').val();
	room.empty();
	room.append("<option value=''>--请选择--</option>");
	$.ajax({
		type : 'post',
		url : 'room/getRoom.action?buildingId=' + buildingId,
		dataType : 'json',
		success : function(data) {
			for(var i=0; i<data.length; i++) {
				room.append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
			}					
		}
	});
}